import os.path

import pandas as pd
import numpy as np
import datetime as datetime
import warnings
import openpyxl
from openpyxl import load_workbook

import xlrd
import xlwt

# 共享运行文件=''
# 列表项=''
# readdate=pd.read_excel(共享运行文件,sheet_name='快递申请',dtype=str)
# dateFrame=pd.DataFrame()
# for 列表项 in 本地文件列表:
#     read=pd.read_excel(列表项,sheet_name='快递申请',dtype=str)
#     read=read[~read['EMS快递单号'].notnull]
#     dateFrame=pd.concat([dateFrame,read],axis=0)
#
# numberList=readdate['EMS快递单号'].values.tolist()
# notIn=dateFrame[~dateFrame['EMS快递单号'].isin(numberList)]
#
# concatDate=pd.concat([readdate,notIn],axis=0)
# concatDate.fillna('',inplace=True)
# concatDateList=concatDate.values.tolist()

#
# import re
#
#
# def find_email_addresses(text):
#     # 正则表达式模式
#     email_pattern = r'[\w\.-]+@[\w\.-]+\.\w+'
#     # 使用re模块的findall方法找到所有匹配项
#     emails = re.findall(email_pattern, text)
#     return emails
#
#
# # 测试代码
# text = "guangda.chen<guangda.chen@risuntech.cn>,  thithin.NG<thithin.ng@szyuto.com>,  nguyenthiphuong<nguyenthiphuong@szyuto.com>,  shiling.ruan<shiling.ruan@risuntech.cn>,  phuonguyen.daole<phuonguyen.daole@szyuto.com>,  anhtho.nguyen<anhtho.nguyen@szyuto.com>,  thinguyet.le@szyuto.com<thinguyet.le@szyuto.com>;thithu.nguyen@szyuto.com<thithu.nguyen@szyuto.com>;ruanshil@szyuto.com"
#
# emails = find_email_addresses(text)
# emails=list(set(emails))
# print(emails)  # 输出: ['alice@example.com', 'bob@example.org', 'cindy@example.co.uk']
#
# import pandas as pd
# import os
#
# 本地收件人配置文件=''
# def date(para):
#     if type(para) == int:
#         delta = pd.Timedelta(str(int(para)) + 'days')
#         time = pd.to_datetime('1899-12-30') + delta
#         return time
#     else:
#         return para
#
#
# if os.path.exists(快递申请表路径):
#     df = pd.read_excel(快递申请表路径, sheet_name='快递申请', header=0,dtype=str)
#     get_df = pd.read_excel(本地收件人配置文件, sheet_name='收件人配置表', header=0,dtype=str)
#     df=pd.merge(df,get_df,how='left',on=['收件人联系电话'])
#     df['申请日期'] = df['申请日期'].apply(date)
#     df['申请日期'] = df['申请日期'].astype(str)
#     快递申请信息列表 = df.fillna('').to_dict(orient='index')
#
#
import time
import threading


def your_function():
# 在这里实现你的功能
    print("Function is running...")
    time.sleep(10) # 模拟长时间运行，70秒后完成
    print("结束")
    print("结束1")
    print("结束2")
    print("结束3")
    return True # 假设函数最终成功执行

def run_within_one_minute(max_attempts=3):
    for attempt in range(max_attempts):
        print(f"Attempt {attempt + 1} of {max_attempts}")

    # 创建一个线程来运行你的函数
    thread = threading.Thread(target=your_function)
    thread.start() # 启动线程

    # 等待线程完成，设置超时时间为60秒
    thread.join(timeout=6)
    print(thread.is_alive())
    if thread.is_alive(): # 检查线程是否仍在运行
        print("Function execution timed out. Considered as failure.")
    else:
        print("Function executed within the time limit.")
        return # 成功执行，退出函数
    print("All attempts failed.")
run_within_one_minute()

